<?php
error_reporting(0);

// Наименование б/д
$dbname="il";

// Для баз
$hostname="localhost";
$username="il";
$password="111111";
mysql_connect($GLOBALS["hostname"],$GLOBALS["username"],$GLOBALS["password"]) or die("");


	header( "Content-Type: text/xml; charset=utf-8" );

	echo( "<?xml version='1.0' encoding='utf-8'?>" );
	echo( "<!-- COPYRIGHT Userplane 2006 (http://www.userplane.com) -->" );
	echo( "<!-- WM version 1.8.13 -->" );
	echo( "<icappserverxml>" );
  
  $tchat=$_GET['tchat'];

	$strDomainID = isset($_GET['domainID']) ? $_GET['domainID'] : null;
	$strFunction = isset($_GET['function']) ? $_GET['function'] : (isset($_GET['action']) ? $_GET['action'] : null);
	$strCallID = isset($_GET['callID']) ? $_GET['callID'] : null;

	if( $strFunction != null && $strDomainID != null )
	{
		$strSessionGUID = isset($_GET['sessionGUID']) ? $_GET['sessionGUID'] : null;
		$strKey = isset($_GET['key']) ? $_GET['key'] : null;
		$strUserID = isset($_GET['memberID']) ? $_GET['memberID'] : null;
		$strTargetUserID = isset($_GET['targetMemberID']) ? $_GET['targetMemberID'] : null;

		if( $strFunction == "getDomainPreferences" )
		{
			// get the value from your database
			echo( "<allowCalls>setBlockedStatus,sendConnectionList,startConversation</allowCalls>" );
			echo( "<characterlimit>200</characterlimit>" );
			echo( "<forbiddenwordslist>ass,bitch</forbiddenwordslist>" );
			echo( "<smileys>" );
				echo( "<smiley>" );
					echo( "<name>Ultra Angry</name>" );
					echo( "<image>http://images.yourCompany.userplane.com/images/smiley/UltraAngry.jpg</image>" );
					echo( "<codes>" );
						echo( "<code><![CDATA[>>:O]]></code>" );
						echo( "<code><![CDATA[>>:-O]]></code>" );
					echo( "</codes>" );
				echo( "</smiley>" );
				echo( "<smiley>" );
					echo( "<name>Angry</name>" );
					echo( "<image>DELETE</image>" );
				echo( "</smiley>" );
			echo( "</smileys>" );
			echo( "<maxvideobandwidth>20000</maxvideobandwidth>" );
			echo( "<domainlogolarge>http://images.clearplane.userplane.com/im/images/UserplaneLogo.jpg</domainlogolarge>" );
			echo( "<line1>Age</line1>" );
			echo( "<line2>Sex</line2>" );
			echo( "<line3>Location</line3>" );
			echo( "<line4></line4>" );
			echo( "<avEnabled>true</avEnabled>" );
			echo( "<clickableUserName>true</clickableUserName>" );
			echo( "<clickableTextUserName>false</clickableTextUserName>" );
			echo( "<gameButton>true</gameButton>" );
			echo( "<buddyListButton>true</buddyListButton>" );
			echo( "<preferencesButton>false</preferencesButton>" );
			echo( "<smileyButton>true</smileyButton>" );
			echo( "<blockButton>false</blockButton>" );
			echo( "<addBuddyEnabled>true</addBuddyEnabled>" );
			echo( "<connectionTimeout>60</connectionTimeout>" );
			echo( "<sendConnectionListInterval>0</sendConnectionListInterval>" );
			echo( "<sendArchive>false</sendArchive>" );
			echo( "<sendTextToImages>false</sendTextToImages>" );
			echo( "<buttonBarColor></buttonBarColor>" );
			echo( "<hideDropShadows>false</hideDropShadows>" );
			echo( "<hideHelp>false</hideHelp>" );
			echo( "<showLocalUserIcon>false</showLocalUserIcon>" );
			echo( "<conferenceCallEnabled>-1</conferenceCallEnabled>" );
			echo( "<maxxmlretries>5</maxxmlretries>" );
			echo( "<buttonIcons>" );
				echo( "<action></action>" );
				echo( "<add></add>" );
				echo( "<block></block>" );
				echo( "<bold></bold>" );
				echo( "<buddyList></buddyList>" );
				echo( "<italic></italic>" );
				echo( "<preferences></preferences>" );
				echo( "<print></print>" );
				echo( "<smiley></smiley>" );
				echo( "<soundOn></soundOn>" );
				echo( "<soundOff></soundOff>" );
				echo( "<underline></underline>" );
			echo( "</buttonIcons>" );
			echo( "<systemMessages>" );
				echo( "<waiting>true</waiting>" );
				echo( "<open>true</open>" );
				echo( "<closed>true</closed>" );
				echo( "<blocked>true</blocked>" );
				echo( "<away>true</away>" );
//				echo( "<nonDeliveryMessage timeout='30' sendOnClose='true' sendOnTimeout='false' promptUser='false'>If [[DISPLAYNAME]] doesn't receive this message, they will be emailed when you close this window</nonDeliveryMessage>" );
				echo( "<nonDeliveryConfirm></nonDeliveryConfirm>" );
//				echo( "<conferenceCallInvitation>Join me in a private anonymous phone call: [[NUMBER]]</conferenceCallInvitation>" );
//				echo( "<conferenceCallReminder>Join a private anonymous phone call: [[NUMBER]]</conferenceCallReminder>" );
//				echo( "<conferenceCallRetrievingNumber>Creating a private anonymous phone number...</conferenceCallRetrievingNumber>" );				
			echo( "</systemMessages>" );
			echo( "<quickMessageList>" );
				echo( "<message>" );
					echo( "<title>Standard greeting</title>" );
					echo( "<body>Welcome! How can I help you today?</body>" );
				echo( "</message>" );
			echo( "</quickMessageList>" );
		}
		else if( $strFunction == "getMemberID" )
		{
			if( $strSessionGUID != null && $strSessionGUID != "" )
			{
				// get the value from your database

				echo( "<memberid>" . $strSessionGUID . "</memberid>" );

				                              $myFile = "/home/il/data/www/www.international-love.com/log.xml";
                                      $fh = fopen($myFile, 'r');
                                      $fileData = fread($fh, filesize($myFile));
                                      $fh = fopen($myFile, 'w') or die("can't open file");
                                      $fileData .= "|memberID=".$_GET['memberID']."|targetMemberID=".$_GET['targetMemberID']."\r\n";
                                      fwrite($fh, $fileData);
                                      fclose($fh);

			}
		}
		else if( $strFunction == "startIC" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				// now that the target user's window is open, we can remove the request from the db
				// the values are reversed because this call happens from the other direction


				                              $myFile = "/home/il/data/www/www.international-love.com/log.xml";
                                      $fh = fopen($myFile, 'r');
                                      $fileData = fread($fh, filesize($myFile));
                                      $fh = fopen($myFile, 'w') or die("can't open file");
                                      $fileData .= "|memberID=".$_GET['memberID']."|targetMemberID=".$_GET['targetMemberID'].$_SESSION['tchat']."\r\n";
                                      fwrite($fh, $fileData);
                                      fclose($fh);

					//--------- find all information |$strUserID| ------------
					// ищем запись

					//f_mysql_update("users", "recorder", $_GET['exists']."|".$_GET['status'], " WHERE user_id=".$_id_user);

					// ищем данные того, КТО вызывает
					$result=mysql_db_query($GLOBALS["dbname"],"
											SELECT sf_guard_user.username as log, 
													inl_gallery.photo_path as filename 
													FROM sf_guard_user, inl_gallery 
													where sf_guard_user.id=inl_gallery.user_id  
													and sf_guard_user.id=".$strUserID);
													
					if (mysql_numrows($result)>0){															
						$find=mysql_fetch_array($result);
						$_name_pic=$find['filename'];
					} else {
						$result=mysql_db_query($GLOBALS["dbname"],"
											SELECT sf_guard_user.username as log
													FROM sf_guard_user
													where sf_guard_user.id=".$strUserID);
						$find=mysql_fetch_array($result);													
						$_name_pic="no_avatar.jpg";						
					}

					// ищем данные того, КОГО вызывает
					$result1=mysql_db_query($GLOBALS["dbname"],"
											SELECT sf_guard_user.username as log, 
												inl_profile.namecity as city,
												YEAR(CURDATE())-YEAR(inl_profile.birthday)-IF(RIGHT(CURDATE(),5) < RIGHT(inl_profile.birthday,5),1,0) as years_old, 
												inl_profile.pol_id 
												FROM sf_guard_user, inl_profile 
												where sf_guard_user.id=inl_profile.user_id
												and sf_guard_user.id=".$strTargetUserID);
													
					$find1=mysql_fetch_array($result1);
					
					
					////Ищем стану
					/*
					$sss="select name from country where id=".$find1['country_id'];
					list($country)=mysql_fetch_row(mysql_db_query($dbname,$sss));
					if(!isset($country)){$country='not set';}
					*/
					$country='not set';
         ///
				
					
					if ($find1['filename']=="") {
						$_name_pic1="_without.jpg";
					} else {
						$_name_pic1=$find1['filename'];
					}
					
					if($find1['pol_id']=='2')
					{
					$gender='woman';
					}
					else
					{
					$gender='man';
					}
					
					/////Добавляем запись в лог
					
					/*
					$sss="insert into chat set master_id=$strUserID , slave_id=$strTargetUserID, type='$tchat', time_start=NOW()";
					mysql_db_query($dbname,$sss);
					*/
					
					// ищем категорию
					//$result2=mysql_db_query($GLOBALS["dbname"],"SELECT English FROM category where Category_id=".$find1['Category']);
					//$find2=mysql_fetch_array($result2);
					//--------------------------------------------------------

					echo( "<member>" );
					echo( "<displayname>".$find['log']."</displayname>" );
					echo( "<imagepath>http://www.international-love.com/uploads/thumbnail/".$_name_pic."</imagepath>" );
					echo( "<avEnabled>true</avEnabled>" );
					echo( "<kissSmackEnabled>true</kissSmackEnabled>" );
					echo( "<showerrors>true</showerrors>" );
					echo( "<sound>true</sound>" );
					echo( "<focus>true</focus>" );
					echo( "<autoOpenAV>false</autoOpenAV>" );
					echo( "<autoStartAudio>false</autoStartAudio>" );
					echo( "<autoStartVideo>false</autoStartVideo>" );
					echo( "<backgroundColor></backgroundColor>" );
					echo( "<fontColor></fontColor>" );
					echo( "<quickMessageList ignoreNoTextEntry='false'>" );
						echo( "<message>" );
							echo( "<title>Standard Greeting</title>" );
							echo( "<body>I'm happy to be here!</body>" );
						echo( "</message>" );
					echo( "</quickMessageList>" );
					echo( "<noTextEntry>false</noTextEntry>" );
					echo( "<sessionTimeout>1800</sessionTimeout>" );
					echo( "<sessionTimeoutMessage>Your session has timed out</sessionTimeoutMessage>" );
					echo( "</member>" );


					echo( "<targetMember>" );
					echo( "<displayname>".$find1['log']."</displayname>" );

					echo( "<line1>".$find1['years_old']."</line1>" );
					echo( "<line2>".$gender."</line2>" );
					echo( "<line3>".$country."</line3>" );

					echo( "<line4></line4>" );

					echo( "<imagepath>http://www.international-love.com/uploads/thumbnail/".$_name_pic1."</imagepath>" );

					echo( "<avEnabled>true</avEnabled>" );
					echo( "<blocked>false</blocked>" );

					echo( "<backgroundColor></backgroundColor>" );
					echo( "<fontColor></fontColor>" );

					echo( "</targetMember>" );

					//---------------------


			}
		}
		else if( $strFunction == "addFriend" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				// handle the request, no response required
			}
		}
		else if( $strFunction == "sendConnectionList" )
		{
			$strXmlData = isset($_POST['xmlData']) ? $_POST['xmlData'] : null;

			if( $strXmlData != null )
			{
				/*
				EXAMPLE:

				<?xml version='1.0' encoding='iso-8859-1'?>
					<connectionList>
					<server>flashcom.yourserver.userplane.com</server>
					<c><f type="m">21</f><t>1</t></c>
					<c><f type="m">1</f><t>8</t></c>
					<c><f type="s">a6d5fe44</f><t>1</t></c>
					<c><f type="m">1</f><t>21</t></c>
				</connectionList>
				*/

				// update your database and no need to return anything
			}
		}
		else if( $strFunction == "setBlockedStatus" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				$bBlocked = isset($_GET['trueFalse']) ? $_GET['trueFalse'] : null;
				$bBlocked = $bBlocked == "true" || $bBlocked == "1";

			// handle the request, no response required
			}
		}
		else if( $strFunction == "startConversation" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				// check to see if there is already a request to open a window in the db

				{
					// if not, insert a request to have a window opened up on the target user's machine

				}
			}
		}
		else if( $strFunction == "notifyConnectionClosed" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				// since the orginating user is closing their window, don't open a window on the target user anymore

       ////Закрытие окна
       
       ////Лог
      
				/*
        mysql_connect($GLOBALS["hostname"],$GLOBALS["username"],$GLOBALS["password"]) or die("");
      	
				
     
       $ss1="select max(id) from chat where master_id=".$_GET['memberID']." and closed=0";
       list($idc)=mysql_fetch_row(mysql_db_query($dbname,$ss1));

       $ss="select UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(time_start) as rz from chat where id=$idc";
       list($rz)=mysql_fetch_row(mysql_db_query($dbname,$ss));
       $rz=ceil($rz/60);
       $ss2="update chat set closed=1, time_end=NOW(), time='$rz' where id=$idc";
       
        mysql_db_query($dbname,$ss2);
      
      ////Отнимаем бабки
      $ss="select gender from profile where user_id=".$_GET['memberID'];
       list($gender)=mysql_fetch_row(mysql_db_query($dbname,$ss));
       if($gender=='m')
       {
          
          $e="select summa from service where id=5";
          list($cena)=mysql_fetch_row(mysql_db_query($dbname,$e));
          
          $e="select count(*) from sf_guard_user_group where user_id=".$_GET['memberID']." and group_id=3";
          list($cn)=mysql_fetch_row(mysql_db_query($dbname,$e));
          if($cn>0)
          { $sm=($cena-($cena*0.1))*$rz;}
          else
          { $sm=$cena*$rz;}
       
      
         $ss="update account set summa=summa-$sm where user_id=".$_GET['memberID'];
         mysql_db_query($dbname,$ss);
       }
      ///
      
      ////Записываем в лог
      $sss="insert into log set user_id=".$_GET['memberID'].", description='video chat', created_at=NOW(), summa='$sm' ";
      mysql_db_query($dbname,$sss);
      ///
      
      ///// 
      */
       
        
				

				                              $myFile = "/home/il/data/www/www.international-love.com/log.xml";
                                      $fh = fopen($myFile, 'r');
                                      $fileData = fread($fh, filesize($myFile));
                                      $fh = fopen($myFile, 'w') or die("can't open file");
                                      $fileData .= "closed|memberID=".$_GET['memberID']."|targetMemberID=".$_GET['targetMemberID'].$s.mysql_affected_rows()."\r\n";
                                      fwrite($fh, $fileData);
                                      fclose($fh);



				// in addition, you can also use the strXmlData variable to get any messages that were never delivered to the targetUser.
				$strXmlData = isset($_POST['xmlData']) ? $_POST['xmlData'] : null;
			}
		}
		else if( $strFunction == "sendPendingMessages" )
		{
			if( $strUserID != null && $strUserID != "" && $strTargetUserID != null && $strTargetUserID != "" )
			{
				// you can use the strXmlData variable to get any messages that were never delivered to the targetUser.
				$strXmlData = isset($_POST['xmlData']) ? $_POST['xmlData'] : null;
			}
		}
		else if( $strFunction == "sendArchive" )
		{
			$strXmlData = isset($_POST['xmlData']) ? $_POST['xmlData'] : null;
		}
	}

	echo( "</icappserverxml>" );
?>

